package com.example.f8399.testdemo.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.example.f8399.testdemo.BaseActivity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.databinding.ActivityDialog2Binding;
import com.example.f8399.testdemo.dialog.MyDialogFragment;
import com.example.f8399.testdemo.dialog.MyDialogFragment2;

public class DialogActivity extends BaseActivity {

    ActivityDialog2Binding mBinding;
    private AlertDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_dialog2);
    }

    public void show1(View view) {
        startActivity(new Intent(this, DialogActivity1.class));
    }

    public void show2(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater inflater = LayoutInflater.from(this);
        View rootView = inflater.inflate(R.layout.dialog_style2, null);
        builder.setView(rootView);

        ImageView iv = rootView.findViewById(R.id.imageView3);
        Glide.with(this).asGif().load(R.raw.aa).into(iv).clearOnDetach();
        Button btn1 = rootView.findViewById(R.id.button18);
        Button btn2 = rootView.findViewById(R.id.button19);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("h1");
                mDialog.dismiss();
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("h2");
                mDialog.dismiss();

            }
        });

//        builder.setCancelable(false);//设定点击dialog外部会不会消失
        mDialog = builder.create();
        mDialog.show();
    }

    /**
     * 显示对话框方式2
     * @param view
     */
    public void show4(View view) {
        MyDialogFragment2 myDialogFragment2 = MyDialogFragment2.newInstance();
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        myDialogFragment2.show(supportFragmentManager,"mydialog2");
    }

    /**
     * 显示对话框方式1
     * @param view
     */
    public void show3(View view) {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        MyDialogFragment myDialogFragment = MyDialogFragment.newInstance();
        myDialogFragment.show(supportFragmentManager,"mydialog");
    }

    public void show5(View view) {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        MyDialogFragment myDialogFragment = MyDialogFragment.newInstance();
        myDialogFragment.show(supportFragmentManager,"mydialog");

    }

}
